package com.xyzwps.server.paimon.conf

import com.fasterxml.jackson.databind.ObjectMapper
import com.xyzwps.server.paimon.graphql.scalar.scalars
import com.xyzwps.server.paimon.jackson.JSON
import com.xyzwps.server.paimon.infra.RestApisFactory
import com.xyzwps.server.paimon.infra.demo.DemoApis
import org.springframework.context.MessageSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.support.ResourceBundleMessageSource
import org.springframework.graphql.execution.RuntimeWiringConfigurer

@Configuration
class Beans {

    @Bean
    fun messageSource(): MessageSource {
        val ms = ResourceBundleMessageSource()
        ms.setBasename("messages")
        ms.setDefaultEncoding("UTF-8")
        return ms
    }

    @Bean
    fun runtimeWiringConfigurer(): RuntimeWiringConfigurer {
        return RuntimeWiringConfigurer {
            for (s in scalars) {
                it.scalar(s)
            }
        }
    }

    @Bean
    fun objectMapper(): ObjectMapper = JSON.OM

    @Bean
    fun demoApis(): DemoApis = RestApisFactory.create(DemoApis::class)
}
